package com.k52group.vn.micromarket;

import static com.k52group.vn.micromarket.CommonUtilities.SENDER_ID;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.google.android.gcm.GCMRegistrar;
import com.google.gson.Gson;
import com.k52group.vn.micromarket.R;
import com.k52group.vn.micromarket.classes.Profile;
import com.k52group.vn.micromarket.utils.Constant;
import com.k52group.vn.micromarket.utils.Utils;

public class HomeActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		registerGCM();
	}

	private String registerGCM() {
		// Make sure the device has the proper dependencies.
		GCMRegistrar.checkDevice(this);

		// Make sure the manifest was properly set - comment out this
		// line
		// while developing the app, then uncomment it when it's ready.
		GCMRegistrar.checkManifest(this);

		// Get GCM registration id
		String regId = GCMRegistrar.getRegistrationId(this);
		System.out.println("regId +" + regId);

		// Check if regid already presents
		if (regId.equals("")) {
			// Registration is not present, register now with GCM
			GCMRegistrar.register(this, SENDER_ID);
		}
		return regId;
	}

	public void onClick(View v) {
		if (v.getId() == R.id.button1) {
			Intent it = new Intent(this, RegisterActivity.class);
			startActivity(it);
			finish();
		}
		if (v.getId() == R.id.Button01) {
			Intent it = new Intent(this, SigninActivity.class);
			startActivity(it);
		}
		if (v.getId() == R.id.Button02) {
			Utils.saveData(Constant.USER, new Gson().toJson(new Profile()), this);
			Intent it = new Intent(this, SearchActivity.class);
			startActivity(it);
		}
		if (v.getId() == R.id.Button03) {
			Intent it = new Intent(this, ContactInfoActivity.class);
			startActivity(it);
		}
	}
}
